<template>
    <div>
        <mt-header title="修改密码">
            <router-link to="/myset" slot="left">
                <i class="mintui mintui-back lic-d"></i>
            </router-link>
        </mt-header>
        <div class="search">
            <input type="password" class="bd" placeholder="原始密码" v-model="kpassword">
            <input type="password" class="bd" placeholder="新密码" v-model="password1">
            <input type="password" class="bd" placeholder="确认密码" v-model="password2">
            <button class="btn" @touchend="postupdatepassword">确定修改</button>
        </div>
    </div>
</template>


<script>
    import {agentselectpassword,updatepassword} from '../api/api'
    import { Toast} from 'mint-ui';

    export default {
        data() {
            return {
                kpassword: '',
                password1: '',
                password2: ''
            }
        },
        methods: {
            postupdatepassword() {
                let agenData = {
                    agentId: sessionStorage.getItem('token'),
                    kpassword: this.kpassword
                }
                console.log(agenData)

                agentselectpassword(agenData).then(res => {
                    console.log(res.data);

                    if (res.data.code == 0) {
                        if (this.password1 === this.password2) {

                            let data = {
                                npassword: this.password1,
                                knpassword: this.password2,
                                agentId: sessionStorage.getItem('token')
                            }
                            console.log(data)

                            updatepassword(data).then(res => {
                                if (res.data.code == 0) {
                                    console.log(res.data);
                                    this.$router.push('/logo')
                                    Toast('修改成功');
                                } else {
                                    Toast('修改失败');
                                }
                            })
                        }
                    }
                })
                 Toast('确认失败');
            }
        }
    }
</script>


<style scoped lang="less">
    a {
        text-decoration: none;
    }
    .lic-d {
        font-size: 50px;
    }
    .mint-header {
        background: -webkit-linear-gradient(left, #6180F4, #79CBFA);
        font-size: 36px;
        height: 80px;
    }
    .search {
        width: 100%;
        box-sizing: border-box;
        padding: 12px 54px;
        margin-bottom: 40px;
        input {
            width: 100%;
            height: 100%;
            outline: 0;
            border: 0;
        }
        .bd {
            border: 2px solid #cccccc;
            border-radius: 10px;
            height: 80px;
            margin-bottom: 20px;
            font-size: 28px;
            padding: 0;
        }
    }
    .btn {
        width: 100%;
        height: 80px;
        display: block;
        background-color: #74B2F8;
        outline: 0;
        border: 0;
        border-radius: 10px;
        margin: 0 auto;
        font-size: 36px;
    }
    .bd::-webkit-input-placeholder {
        color: #aab2bd;
        font-size: 28px;
        padding-left: 10px;
    }
</style>